import Vue from 'vue'

window.eventBus = new Vue()
const android = window.android || {}

export function closeWebView() {
  // android.closeWebView && android.closeWebView()
  window.WebViewJavascriptBridge.callHandler(
    'closeWebView'
    , { }
    , function () {}
  )
}

export function isAndroid() {
  return android.isAndroid && android.isAndroid()
}

export function getUserInfo() {
  return android.getUserInfo && JSON.parse(android.getUserInfo())
}

export function getReportCacheData() {
  return android.getReportCacheData && JSON.parse(android.getReportCacheData())
}

export function openMap(cb) {
  window.eventBus.$on("getaddress", cb)
  android.openMap && android.openMap()
}
window.returnMapData = function(result) {
  window.eventBus.$emit("getaddress", JSON.parse(result))
  window.eventBus.$off("getaddress")
}
export function getRootUrl() {
  return android.getRootUrl && android.getRootUrl()
}
export function getImgUrl() {
  return android.getImgUrl && android.getImgUrl()
}